1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Scale; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gtk.Adjustment; 31 private import gtk.Range; 32 private import gtk.Widget; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 private import pango.PgLayout; 36 37 38 /** 39 * A `GtkScale` is a slider control used to select a numeric value. 40 * 41 *  42 * 43 * To use it, you’ll probably want to investigate the methods on its base 44 * class, [class@GtkRange], in addition to the methods for `GtkScale` itself. 45 * To set the value of a scale, you would normally use [method@Gtk.Range.set_value]. 46 * To detect changes to the value, you would normally use the 47 * [signal@Gtk.Range::value-changed] signal. 48 * 49 * Note that using the same upper and lower bounds for the `GtkScale` (through 50 * the `GtkRange` methods) will hide the slider itself. This is useful for 51 * applications that want to show an undeterminate value on the scale, without 52 * changing the layout of the application (such as movie or music players). 53 * 54 * # GtkScale as GtkBuildable 55 * 56 * `GtkScale` supports a custom <marks> element, which can contain multiple 57 * <mark\> elements. The “value” and “position” attributes have the same 58 * meaning as [method@Gtk.Scale.add_mark] parameters of the same name. If 59 * the element is not empty, its content is taken as the markup to show at 60 * the mark. It can be translated with the usual ”translatable” and 61 * “context” attributes. 62 * 63 * # CSS nodes 64 * 65 * ``` 66 * scale[.fine-tune][.marks-before][.marks-after] 67 * ├── [value][.top][.right][.bottom][.left] 68 * ├── marks.top 69 * │ ├── mark 70 * │ ┊ ├── [label] 71 * │ ┊ ╰── indicator 72 * ┊ ┊ 73 * │ ╰── mark 74 * ├── marks.bottom 75 * │ ├── mark 76 * │ ┊ ├── indicator 77 * │ ┊ ╰── [label] 78 * ┊ ┊ 79 * │ ╰── mark 80 * ╰── trough 81 * ├── [fill] 82 * ├── [highlight] 83 * ╰── slider 84 * ``` 85 * 86 * `GtkScale` has a main CSS node with name scale and a subnode for its contents, 87 * with subnodes named trough and slider. 88 * 89 * The main node gets the style class .fine-tune added when the scale is in 90 * 'fine-tuning' mode. 91 * 92 * If the scale has an origin (see [method@Gtk.Scale.set_has_origin]), there is 93 * a subnode with name highlight below the trough node that is used for rendering 94 * the highlighted part of the trough. 95 * 96 * If the scale is showing a fill level (see [method@Gtk.Range.set_show_fill_level]), 97 * there is a subnode with name fill below the trough node that is used for 98 * rendering the filled in part of the trough. 99 * 100 * If marks are present, there is a marks subnode before or after the trough 101 * node, below which each mark gets a node with name mark. The marks nodes get 102 * either the .top or .bottom style class. 103 * 104 * The mark node has a subnode named indicator. If the mark has text, it also 105 * has a subnode named label. When the mark is either above or left of the 106 * scale, the label subnode is the first when present. Otherwise, the indicator 107 * subnode is the first. 108 * 109 * The main CSS node gets the 'marks-before' and/or 'marks-after' style classes 110 * added depending on what marks are present. 111 * 112 * If the scale is displaying the value (see [property@Gtk.Scale:draw-value]), 113 * there is subnode with name value. This node will get the .top or .bottom style 114 * classes similar to the marks node. 115 * 116 * # Accessibility 117 * 118 * `GtkScale` uses the %GTK_ACCESSIBLE_ROLE_SLIDER role. 119 */ 120 public class Scale : Range 121 { 122 /** the main Gtk struct */ 123 protected GtkScale* gtkScale; 124 125 /** Get the main Gtk struct */ 126 public GtkScale* getScaleStruct(bool transferOwnership = false) 127 { 128 if (transferOwnership) 129 ownedRef = false; 130 return gtkScale; 131 } 132 133 /** the main Gtk struct as a void* */ 134 protected override void* getStruct() 135 { 136 return cast(void*)gtkScale; 137 } 138 139 /** 140 * Sets our main struct and passes it to the parent class. 141 */ 142 public this (GtkScale* gtkScale, bool ownedRef = false) 143 { 144 this.gtkScale = gtkScale; 145 super(cast(GtkRange*)gtkScale, ownedRef); 146 } 147 148 149 /** */ 150 public static GType getType() 151 { 152 return gtk_scale_get_type(); 153 } 154 155 /** 156 * Creates a new `GtkScale`. 157 * 158 * Params: 159 * orientation = the scale’s orientation. 160 * adjustment = the [class@Gtk.Adjustment] which sets 161 * the range of the scale, or %NULL to create a new adjustment. 162 * 163 * Returns: a new `GtkScale` 164 * 165 * Throws: ConstructionException GTK+ fails to create the object. 166 */ 167 public this(GtkOrientation orientation, Adjustment adjustment) 168 { 169 auto __p = gtk_scale_new(orientation, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 170 171 if(__p is null) 172 { 173 throw new ConstructionException("null returned by new"); 174 } 175 176 this(cast(GtkScale*) __p); 177 } 178 179 /** 180 * Creates a new scale widget with a range from @min to @max. 181 * 182 * The returns scale will have the given orientation and will let the 183 * user input a number between @min and @max (including @min and @max) 184 * with the increment @step. @step must be nonzero; it’s the distance 185 * the slider moves when using the arrow keys to adjust the scale 186 * value. 187 * 188 * Note that the way in which the precision is derived works best if 189 * @step is a power of ten. If the resulting precision is not suitable 190 * for your needs, use [method@Gtk.Scale.set_digits] to correct it. 191 * 192 * Params: 193 * orientation = the scale’s orientation. 194 * min = minimum value 195 * max = maximum value 196 * step = step increment (tick size) used with keyboard shortcuts 197 * 198 * Returns: a new `GtkScale` 199 * 200 * Throws: ConstructionException GTK+ fails to create the object. 201 */ 202 public this(GtkOrientation orientation, double min, double max, double step) 203 { 204 auto __p = gtk_scale_new_with_range(orientation, min, max, step); 205 206 if(__p is null) 207 { 208 throw new ConstructionException("null returned by new_with_range"); 209 } 210 211 this(cast(GtkScale*) __p); 212 } 213 214 /** 215 * Adds a mark at @value. 216 * 217 * A mark is indicated visually by drawing a tick mark next to the scale, 218 * and GTK makes it easy for the user to position the scale exactly at the 219 * marks value. 220 * 221 * If @markup is not %NULL, text is shown next to the tick mark. 222 * 223 * To remove marks from a scale, use [method@Gtk.Scale.clear_marks]. 224 * 225 * Params: 226 * value = the value at which the mark is placed, must be between 227 * the lower and upper limits of the scales’ adjustment 228 * position = where to draw the mark. For a horizontal scale, %GTK_POS_TOP 229 * and %GTK_POS_LEFT are drawn above the scale, anything else below. 230 * For a vertical scale, %GTK_POS_LEFT and %GTK_POS_TOP are drawn to 231 * the left of the scale, anything else to the right. 232 * markup = Text to be shown at the mark, using Pango markup 233 */ 234 public void addMark(double value, GtkPositionType position, string markup) 235 { 236 gtk_scale_add_mark(gtkScale, value, position, Str.toStringz(markup)); 237 } 238 239 /** 240 * Removes any marks that have been added. 241 */ 242 public void clearMarks() 243 { 244 gtk_scale_clear_marks(gtkScale); 245 } 246 247 /** 248 * Gets the number of decimal places that are displayed in the value. 249 * 250 * Returns: the number of decimal places that are displayed 251 */ 252 public int getDigits() 253 { 254 return gtk_scale_get_digits(gtkScale); 255 } 256 257 /** 258 * Returns whether the current value is displayed as a string 259 * next to the slider. 260 * 261 * Returns: whether the current value is displayed as a string 262 */ 263 public bool getDrawValue() 264 { 265 return gtk_scale_get_draw_value(gtkScale) != 0; 266 } 267 268 /** 269 * Returns whether the scale has an origin. 270 * 271 * Returns: %TRUE if the scale has an origin. 272 */ 273 public bool getHasOrigin() 274 { 275 return gtk_scale_get_has_origin(gtkScale) != 0; 276 } 277 278 /** 279 * Gets the `PangoLayout` used to display the scale. 280 * 281 * The returned object is owned by the scale so does not need 282 * to be freed by the caller. 283 * 284 * Returns: the [class@Pango.Layout] 285 * for this scale, or %NULL if the [property@GtkScale:draw-value] 286 * property is %FALSE. 287 */ 288 public PgLayout getLayout() 289 { 290 auto __p = gtk_scale_get_layout(gtkScale); 291 292 if(__p is null) 293 { 294 return null; 295 } 296 297 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) __p); 298 } 299 300 /** 301 * Obtains the coordinates where the scale will draw the 302 * `PangoLayout` representing the text in the scale. 303 * 304 * Remember when using the `PangoLayout` function you need to 305 * convert to and from pixels using `PANGO_PIXELS()` or `PANGO_SCALE`. 306 * 307 * If the [property@GtkScale:draw-value] property is %FALSE, the return 308 * values are undefined. 309 * 310 * Params: 311 * x = location to store X offset of layout 312 * y = location to store Y offset of layout 313 */ 314 public void getLayoutOffsets(out int x, out int y) 315 { 316 gtk_scale_get_layout_offsets(gtkScale, &x, &y); 317 } 318 319 /** 320 * Gets the position in which the current value is displayed. 321 * 322 * Returns: the position in which the current value is displayed 323 */ 324 public GtkPositionType getValuePos() 325 { 326 return gtk_scale_get_value_pos(gtkScale); 327 } 328 329 /** 330 * Sets the number of decimal places that are displayed in the value. 331 * 332 * Also causes the value of the adjustment to be rounded to this number 333 * of digits, so the retrieved value matches the displayed one, if 334 * [property@GtkScale:draw-value] is %TRUE when the value changes. If 335 * you want to enforce rounding the value when [property@GtkScale:draw-value] 336 * is %FALSE, you can set [property@GtkRange:round-digits] instead. 337 * 338 * Note that rounding to a small number of digits can interfere with 339 * the smooth autoscrolling that is built into `GtkScale`. As an alternative, 340 * you can use [method@Gtk.Scale.set_format_value_func] to format the displayed 341 * value yourself. 342 * 343 * Params: 344 * digits = the number of decimal places to display, 345 * e.g. use 1 to display 1.0, 2 to display 1.00, etc 346 */ 347 public void setDigits(int digits) 348 { 349 gtk_scale_set_digits(gtkScale, digits); 350 } 351 352 /** 353 * Specifies whether the current value is displayed as a string next 354 * to the slider. 355 * 356 * Params: 357 * drawValue = %TRUE to draw the value 358 */ 359 public void setDrawValue(bool drawValue) 360 { 361 gtk_scale_set_draw_value(gtkScale, drawValue); 362 } 363 364 /** 365 * @func allows you to change how the scale value is displayed. 366 * 367 * The given function will return an allocated string representing 368 * @value. That string will then be used to display the scale's value. 369 * 370 * If #NULL is passed as @func, the value will be displayed on 371 * its own, rounded according to the value of the 372 * [property@GtkScale:digits] property. 373 * 374 * Params: 375 * func = function that formats the value 376 * userData = user data to pass to @func 377 * destroyNotify = destroy function for @user_data 378 */ 379 public void setFormatValueFunc(GtkScaleFormatValueFunc func, void* userData, GDestroyNotify destroyNotify) 380 { 381 gtk_scale_set_format_value_func(gtkScale, func, userData, destroyNotify); 382 } 383 384 /** 385 * Sets whether the scale has an origin. 386 * 387 * If [property@GtkScale:has-origin] is set to %TRUE (the default), 388 * the scale will highlight the part of the trough between the origin 389 * (bottom or left side) and the current value. 390 * 391 * Params: 392 * hasOrigin = %TRUE if the scale has an origin 393 */ 394 public void setHasOrigin(bool hasOrigin) 395 { 396 gtk_scale_set_has_origin(gtkScale, hasOrigin); 397 } 398 399 /** 400 * Sets the position in which the current value is displayed. 401 * 402 * Params: 403 * pos = the position in which the current value is displayed 404 */ 405 public void setValuePos(GtkPositionType pos) 406 { 407 gtk_scale_set_value_pos(gtkScale, pos); 408 } 409 }